package com.zsh.rabbitmq.two;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.zsh.rabbitmq.utils.RabbitMQUtils;

/**
 * @author zsh
 * @Description 这是一个工作线程，相当于消费者
 * @create 2022-04-26 14:03
 */
public class Worker01 {
    public static final String QUEUE_NAME = "hello";

    //接收消息
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtils.getChannel();

        //声明 接收消息 lambda 表达式
        DeliverCallback deliverCallback = (consumerTag, msg) -> {
            String msgString = new String(msg.getBody());
            System.out.println("接收到的消息：" + msgString);
        };

        //声明 取消消息 lambda 表达式
        CancelCallback cancelCallback = consumerTag -> {
            System.out.println(consumerTag + "消息被取消");
        };

        System.out.println("c2等待接收消息。。。。。");

        //消息的接收
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);
    }
}
